rm(list = setdiff(ls(), lsf.str()))
#Load data 2007
data<-haven::read_dta("Study 1/Original Data/1380933774venezuela_lapop_dims2007dataset.dta")

#Neuroticism ----
data$n_tense <- data$per1 #PER1: tense
data$n_nervous_rec <- 10-data$per6 #PER6. nervous
data$neu <- rowMeans(data.frame(data$n_tense, data$n_nervous_rec), na.rm=T)


#Extraversoin ----
data$e_talkative_rec<-10-data$per2 
data$e_outgoing <- data$per5 
data$ext <- rowMeans(data.frame(data$e_talkative_rec, data$e_outgoing), na.rm=T)

#conscientiousness----
data$c_hardworker_rec<-10-data$per3 
data$c_ordered <- data$per10
data$con <- rowMeans(data.frame(data$c_hardworker_rec, data$c_ordered), na.rm=T)


#Openness ----
data$o_thoughtful_rec <- 10-data$per4 
data$o_intellectual<- data$per8 
data$open <- rowMeans(data.frame(data$o_thoughtful_rec, data$o_intellectual), na.rm=T)


#Agreeableness---
data$a_nice_rec<-10-(data$per7) 
data$a_kind<-data$per9 
data$agre <- rowMeans(data.frame(data$a_nice_rec, data$a_kind), na.rm=T)

#age
data$age<-data$q2
#sex
data$female<-ifelse(data$q1==2,1,0)

#education ---
data$education_years <- data$ed
#Vote populist: Chavez
#data$vote_populist[data$vb2==2 | data$vb3==1602 | data$vb3==1677 | data$vb3==0]=0
#data$vote_populist[data$vb3==1601]=1

data$vote_populist[data$vb3==1602 | data$vb3==1677 | data$vb3==0]=0
data$vote_populist[data$vb3==1601]=1

#Vote Chavez in 2006
#data$vote_chavez06<-ifelse(data$vb3==1601,1,0)

#left-right----
data$lr_placement <- data$l1
data$lr_placement[is.na(data$lr_placement)] <- 11
data$lr_placement_missing<-ifelse(data$lr_placement==11,1,0)

#income
data$income<-data$q10
data$income<-zero1(data$income)
data$income[is.na(data$income)] <- 2
data$income_missing<-ifelse(data$income==2,1,0)

#ethnicity
data$ethnicity<-data$etid

#turnout
data$didnotvote<- ifelse(data$vb2==2, 1, 0)

#populist, other, did not vote--------
data$populist_other_not <- data$vote_populist
data$populist_other_not[data$didnotvote==1]=2

#save
save(data, file="Study 1/Altered Data/Study1_Venezuela07.RData")

